﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsFeeBeforeDAL.cs
/// 作  者：SAM
/// 时  间：2007.01.11
/// 说  明：ClsFeeBeforeDAL类用于费用预算信息相关处理
/// </summary>
public class ClsFeeBeforeDAL
{
    #region  数据库连接字符串
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    #endregion

    #region  费用预算数据访问层主体部分

    // 获取费用预算主单信息
    public DataSet GetFeeBeforeDataSet(string UserID, int Type)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetFeeBeforeM", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.NVarChar, 60);
        dat.SelectCommand.Parameters["@u_log_id"].Value = UserID;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 4);
        dat.SelectCommand.Parameters["@type"].Value = Type;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    // 获取所有费用预算从表信息
    public DataSet GetFeeBeforeChildDataSet(string No)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetFeeBeforeD", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@f_no", SqlDbType.NVarChar, 50);
        dat.SelectCommand.Parameters["@f_no"].Value = No;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    // 作废费用预算主表
    public Boolean DeleteInfo(int ID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteFeeBeforeInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 作废费用预算从表
    public Boolean DeleteChildInfo(int ID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteFeeBeforeChildInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 确认或取消确认费用预算
    public Boolean AuditOrOAuditFeeBeforeInfo(int ID, string UserID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditOrOAuditFeeBeforeInfo", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@user", SqlDbType.NVarChar, 50);
        com.Parameters["@user"].Value = UserID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 新增或修改费用预算主表信息
    public Boolean AddOrUpdateInfo(int ID, string No, DateTime Date, string Dp_No, string Oper, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddOrUpdateFeeBeforeInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@f_no", SqlDbType.NVarChar, 50);
        com.Parameters["@f_no"].Value = No;
        com.Parameters.Add("@f_date", SqlDbType.DateTime, 8);
        com.Parameters["@f_date"].Value = Date;
        com.Parameters.Add("@dp_id", SqlDbType.NVarChar, 50);
        com.Parameters["@dp_id"].Value = Dp_No;
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 50);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 新增或修改费用预算从表信息
    public Boolean AddOrUpdateChild(int ID, string f_no, string im_no, decimal a_money, decimal b_money, decimal c_money, decimal d_money, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddOrUpdateFeeBeforeChildInfo ", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@f_no", SqlDbType.NVarChar, 30);
        com.Parameters["@f_no"].Value = f_no;
        com.Parameters.Add("@im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@im_no"].Value = im_no;

        com.Parameters.Add("@a_money", SqlDbType.Decimal);
        com.Parameters["@a_money"].Value = a_money;
        com.Parameters.Add("@b_money", SqlDbType.Decimal);
        com.Parameters["@b_money"].Value = b_money;
        com.Parameters.Add("@c_money", SqlDbType.Decimal);
        com.Parameters["@c_money"].Value = c_money;
        com.Parameters.Add("@d_money", SqlDbType.Decimal);
        com.Parameters["@d_money"].Value = d_money;

        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;


        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    #endregion

    #region  费用预算数据访问层其他部分

    #endregion
}
